package com.lute.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

import javax.servlet.http.HttpSession;

import net.sf.jasperreports.engine.JRDataSource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.lute.model.Approver;
import com.lute.model.Employee;
import com.lute.model.EmployeeAccountingPeriod;
import com.lute.model.EmployeeAccountingPeriodState;
import com.lute.model.Role;
import com.lute.report.LuteSummaryReport;
import com.lute.utils.DAOFactory;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
	/**
	 * Only for test purpose.
	 */
	
	@RequestMapping(value = "/home", method = RequestMethod.GET)
	public String home(@RequestBody String credentials) {
		//logger.info("Welcome home! The client locale is {}.", locale);
		
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		//SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		GregorianCalendar cal = new GregorianCalendar();
		dateFormater.setCalendar(cal);
		System.out.println(dateFormater.format(cal.getTime()));
		System.out.println("Home");
		
//		String [] bcc = new String[3];
//		bcc[0] = "bartosz.szewczyk.81@gmail.com";
//		bcc[1] = "adam.ludwikowski@gmail.com";
//		bcc[2] = "rafalmigalski@gmail.com";
//		SendMail.getInstance().sendMassMail(bcc, "What's up ?");
//		SendMail.getInstance().sendMailTo("rafalmigalski@gmail.com", "What's up ?");
//		Approver app = (Approver)DAOFactory.getInstance().getLuteInterface().getUserFromDatabase("login", "applogin");
//		System.out.println("jestem");
//		List<Employee> e = app.getEmployees();
//		for(Employee ep : e) {
//			System.out.println(ep.getBusinessUnit().getName());
//			System.out.println(app.getRole().getName());
//		}
//		ClientAdmin app = (ClientAdmin)DAOFactory.getInstance().getLuteInterface().getUserFromDatabase("login", "mietek");
//		System.out.println("jestem");
//		List<Client> e = app.getClients();
//		for(Client ep : e) {
//			System.out.println(ep.getName());
//			System.out.println(app.getLogin());
//		}
		
//		Employee employee = DAOFactory.getInstance().getLuteInterface().getEmployeeFromDataBaseById("id_user", 10);
//		Approver approver = new Approver();
//		approver.setId_user(employee.getId_user());
//		approver.setEmail(employee.getEmail());
//		approver.setFirst_name(employee.getFirst_name());
//		approver.setLast_name(employee.getLast_name());
//		approver.setRole(Role.getRoleFromDB("approver"));
//		approver.setLogin(employee.getLogin());
//		approver.setPassword_hash(employee.getPassword_hash());
//		DAOFactory.getInstance().getLuteInterface().changeObjectType(approver, employee.getId_user(), Employee.class, "id_user", "User_Type", "Approver");

//		Approver approver = DAOFactory.getInstance().getLuteInterface().getApproverFromDataBaseById("id_user", 10);
//		approver.setRole(Role.getRoleFromDB("approver"));
//		DAOFactory.getInstance().getLuteInterface().updateObjectinDataBase(approver);
		
//		Approver approver = DAOFactory.getInstance().getLuteInterface().getApproverFromDataBaseByIdWithAll("id_user", 10);
//		Employee employee = DAOFactory.getInstance().getLuteInterface().getEmployeeFromDataBaseById("id_user", 9);
//		EmployeeAccountingPeriod emp = new EmployeeAccountingPeriod();
//		emp.setApprover(approver);
//		emp.setEmployeeAccountingPeriodState(EmployeeAccountingPeriodState.CHECKED_BY_APPROVER.toString());
//		approver.getApproverAccountingPeriods().add(emp);
//		approver.getEmployees().add(employee);
//		DAOFactory.getInstance().getLuteInterface().updateObjectinDataBase(approver);
		return "getperson";
	}

//	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
//	@ResponseStatus(HttpStatus.OK)
//	public @ResponseBody /*JSONTest*/String getJSON(@PathVariable String name) {
//		
//		//JSONTest test = new JSONTest();
////		test.setName(name);
////		test.setStaffName(new String[]{"rafal","migalski"});
//		return "test";
//	}
}
